import React, { Component } from 'react';
import { Link }from 'react-router-dom';
import { Breadcrumb  } from 'antd';

//具体导航的名称
const breadcrumbNameMap = {
    "dashboard":'后台概览',    
    "index":'首页',    
    "infoManage":'信息概览',
    "viewChart":'图表一览',
    "dataMonitor":'大数据云监控',
    "cityInfo":'城区数据管理',
    "scenicSpot":'旅游景点管理',
    "develop":'生产管理',
    "cityData":"城区数据",
    "peopleLive":'民生问题',
    "alarmMgmt":'告警中心',
    "list":'云服务告警',
    "config":'处置警告',
    "environment":'生态环境污染',
    "cityInfo":"城区数据管理",
    "maps":'地图管理',
    "mapInformation":'地图数据',
    "point":'资源标记管理',
    "center":'管理中心',
    "person":'个人中心',
    "user":'用户管理中心',
    "cityPlan":'城市规划',
    "infoDetail":'数据详情',
    "approvalDetail":'审批详情',
    "project":'工程管理',
    "account":'账号设置',
    "itemPlan":'项目规划',
}
export default class extends Component {
    constructor(props) {
        super(props);
        this.state={
            pathSnippets: null,
            extraBreadcrumbItems: null,
            arrgs:[]
        }
    }
    getPath = () => {
        //对路径进行切分，存放到this.state.pathSnippets中
        this.state.pathSnippets = this.props.props.location.pathname.replace('/index','/index');
        this.state.arrgs = this.state.pathSnippets.split('/').filter(i => i);
        this.state.extraBreadcrumbItems = this.state.arrgs.map((_,index)=>{
            return (
                <Breadcrumb.Item key={_}>
                        {breadcrumbNameMap[_]}
                </Breadcrumb.Item>
            );
        })
        // this.state.extraBreadcrumbItems = this.state.pathSnippets.map((_, index) => {
        //     let url = `/${this.state.pathSnippets.slice(0, index + 1).join('/')}`;
        //     return (
        //         <Breadcrumb.Item key={url}>
        //             <Link to={url}>
        //                 {breadcrumbNameMap[url]}
        //             </Link>
        //         </Breadcrumb.Item>
        //     );
        // });        


        // this.state.pathSnippets = this.props.pathname.split('/').filter(i => i);
        // let arr=this.state.pathSnippets;
        // let pathname=this.context.router.history.location.pathname;
        // 将切分的路径读出来，形成面包屑，存放到this.state.extraBreadcrumbItems
        // this.state.extraBreadcrumbItems = this.state.pathSnippets.map((_, index) => {
        //     let url = `/${this.state.pathSnippets.slice(0, index + 1).join('/')}`;
        //     return (
        //         <Breadcrumb.Item key={url}>
        //             <Link to={url}>
        //                 {breadcrumbNameMap[url]}
        //             </Link>
        //         </Breadcrumb.Item>
        //     );
        // });
    }

    authLogin = () =>{
        let tokens = window.sessionStorage.getItem('tokens');
        if(tokens === '' || tokens === undefined || tokens === null){
            // this.props.history.push('/index/dashboard/infoManage');
            window.sessionStorage.clear(); //删除所有值。
            let host = window.location.origin;
            window.location =`${host}/#/login`;
        }
    }

    componentWillMount() {
        this.getPath();
        this.authLogin();
    }
    render() {
        return <Breadcrumb style={{width:250,height:30,lineHeight:'60px',textAlign:'left',marginLeft:36}}>{this.state.extraBreadcrumbItems}</Breadcrumb>;
    }
}